package com.tool_stdy.thread;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * Created by yan_li on 2016/1/10.
 */
public class ThreadSave implements Runnable{
    static ThreadSave sync = new ThreadSave();
    static volatile int j=0;
    Lock  lock =new ReentrantLock();
    public  void inscane(){
       lock.lock();
        for(int i=0;i<10000000;i++){
            j++;
        }
        lock.unlock();
    }
    @Override
    public void run() {
        inscane();
    }
    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(sync);
        Thread t2 = new Thread(sync);
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        System.out.println(j);
    }
}
